#include <iostream>
#include <stdio.h>
#include <string.h>
#include <set>
#include <queue>
typedef long long LL;
using namespace std;
const int MAXN = 2e5+7;
LL arr[MAXN];

int main(int argc, char** argv) {
#ifdef hai
    freopen("in.txt", "r", stdin);
#endif
    int T, n;
    scanf("%d", &T);
    priority_queue<LL, vector<LL>, greater<LL> > pq;
    multiset<LL> sset;
    while (T--) {
        while(!pq.empty()) pq.pop();
        sset.clear();
        scanf("%d", &n);
        for (int i=0; i<n; ++i) {
            scanf("%lld", arr+i);
        }
        LL profit=0, ti=0;
        for (int i=0; i<n; ++i) {
            if (!pq.empty() && pq.top()<arr[i]) {
                LL t = pq.top();
                if (sset.count(t)) {
                    profit += (arr[i] - t);
                    sset.erase(sset.find(t));
                }
                else {
                    ++ti;
                    profit += (arr[i] - t);
                    pq.pop();
                }
                sset.insert(arr[i]);
            }
            pq.push(arr[i]);
        }
        cout<<profit<<" "<<ti*2<<endl;
    }
    return 0;
}
